/**
 * Created by Jiang Xiao Er 2019/7/10.
 * 
 * 
 */
'use strict';
const webpack = require('webpack');
const path = require('path');
const cleanWebpackPlugin = require('clean-webpack-plugin');
var nodeExternals = require('webpack-node-externals');
const MinifyPlugin = require('babel-minify-webpack-plugin');
var babelpolyfill = require("babel-polyfill");
module.exports = {
    entry: path.resolve(__dirname, 'app.js'), //入口文件
    output: {
        path: path.resolve(__dirname,'build'), //输出路径
        filename: 'app.js'//输出后的文件名
    },
    module: {
        loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            use: [{
                loader: 'babel-loader',
                options: {
                    presets: ['es2015', 'stage-3'] //兼容es6，并添加.babelrc
                }
            }]

        }]
    },
    target: 'node', // 服务端打包
    externals: [nodeExternals()], //node 打包可去除一些警告
    resolve: {
        modules: [
            'node_modules',
            path.resolve(__dirname, 'app')
        ]
    },
    plugins: [
        new webpack.DefinePlugin({
            "process.env":{
              NODE_ENV:JSON.stringify('production')
             }
          }),
        new cleanWebpackPlugin(['./build/app.js'], {
            root: path.resolve(__dirname, './')
        }),
        new MinifyPlugin() //压缩js
    ]
    
};